package com.ruoyi.base.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.entity.MiniAppUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

/**
 * 
 * @TableName client_user
 */
@TableName(value ="client_user")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ClientUser extends BaseEntity implements Serializable {

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    /** id */
    private Long id;

    /** 小程序 */
    private String appId;

    /** 小程序openid */
    @Excel(name = "小程序openid")
    private String openId;

    /** 昵称 */
    @Excel(name = "昵称")
    private String nickName;

    /** 手机号 */
    @Excel(name = "手机号")
    private String phoneNumber;

    /** 头像地址 */
    @Excel(name = "头像地址")
    private String headimgUrl;

    /** 显示顺序 */
    private Long orderNum;

    /** 删除标识 */
    private Long delFlag;


    public static ClientUser buildDefaultClientUser(String appId, String openid)
    {
        ClientUser clientUser = new ClientUser();
        clientUser.setAppId(appId);
        clientUser.setNickName("微信用户");
        clientUser.setOpenId(openid);
        return clientUser;
    }

    public LoginUser adapterLoginUser(){
        MiniAppUser miniAppUser = new MiniAppUser();
        BeanUtils.copyProperties(this,miniAppUser);
        LoginUser loginUser = new LoginUser(miniAppUser);
        loginUser.setUserId(Long.valueOf(miniAppUser.getId()));
        return loginUser;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        ClientUser other = (ClientUser) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getAppId() == null ? other.getAppId() == null : this.getAppId().equals(other.getAppId()))
            && (this.getOpenId() == null ? other.getOpenId() == null : this.getOpenId().equals(other.getOpenId()))
            && (this.getNickName() == null ? other.getNickName() == null : this.getNickName().equals(other.getNickName()))
            && (this.getPhoneNumber() == null ? other.getPhoneNumber() == null : this.getPhoneNumber().equals(other.getPhoneNumber()))
            && (this.getHeadimgUrl() == null ? other.getHeadimgUrl() == null : this.getHeadimgUrl().equals(other.getHeadimgUrl()))
            && (this.getOrderNum() == null ? other.getOrderNum() == null : this.getOrderNum().equals(other.getOrderNum()))
            && (this.getDelFlag() == null ? other.getDelFlag() == null : this.getDelFlag().equals(other.getDelFlag()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getAppId() == null) ? 0 : getAppId().hashCode());
        result = prime * result + ((getOpenId() == null) ? 0 : getOpenId().hashCode());
        result = prime * result + ((getNickName() == null) ? 0 : getNickName().hashCode());
        result = prime * result + ((getPhoneNumber() == null) ? 0 : getPhoneNumber().hashCode());
        result = prime * result + ((getHeadimgUrl() == null) ? 0 : getHeadimgUrl().hashCode());
        result = prime * result + ((getOrderNum() == null) ? 0 : getOrderNum().hashCode());
        result = prime * result + ((getDelFlag() == null) ? 0 : getDelFlag().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", app_id=").append(appId);
        sb.append(", open_id=").append(openId);
        sb.append(", nick_name=").append(nickName);
        sb.append(", phone_number=").append(phoneNumber);
        sb.append(", headimg_url=").append(headimgUrl);
        sb.append(", order_num=").append(orderNum);
        sb.append(", del_flag=").append(delFlag);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}